local fengji_other = fk.CreateSkill {
  name = "th_fengji&",
}

fengji_other:addEffect("active", {
  anim_type = "support",
  mute = true,
  prompt = function(self, player, cards, targets)
    return #targets == 1 and "#th_fengji&:" .. targets[1].id .. "::" .. targets[1]:getMark("@th_fengji") + 1 or "#th_fengji&0"
  end,
  can_use = function(self, player)
    return table.find(Fk:currentRoom().alive_players, function(p)
      return p:hasSkill("th_fengji") and p ~= player and
      Fk.skill_skels["th_fengji"]:withinTimesLimit(p, Player.HistoryPhase)
    end) and not player:isKongcheng()
  end,
  card_num = 1,
  card_filter = function(self, player, to_select, selected)
    return #selected < 1 and Fk:getCardById(to_select).color == Card.Red and Fk:currentRoom():getCardArea(to_select) == Player.Hand
  end,
  target_num = function(self, player)
    if #table.filter(Fk:currentRoom().alive_players, function(p)
      return p:hasSkill("th_fengji") and p ~= player and Fk.skill_skels["th_fengji"]:withinTimesLimit(p, Player.HistoryPhase)
    end) > 1 then
      return 1
    else
      return 0
    end
  end,
  target_filter = function(self, player, to_select, selected)
    if #table.filter(Fk:currentRoom().alive_players, function(p)
      return p:hasSkill("th_fengji") and p ~= player and Fk.skill_skels["th_fengji"]:withinTimesLimit(p, Player.HistoryPhase)
    end) > 1 then
      return #selected == 0 and to_select ~= player and to_select:hasSkill("th_fengji") and Fk.skill_skels["th_fengji"]:withinTimesLimit(to_select, Player.HistoryPhase)
    else
      return false
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local targets = effect.tos[1] and effect.tos or table.filter(room.alive_players, function(p)
      return p:hasSkill("th_fengji") and p ~= player and Fk.skill_skels["th_fengji"]:withinTimesLimit(p, Player.HistoryPhase)
    end)
    local minoriko
    if #targets == 1 then
      minoriko = targets[1]
    else
      minoriko = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = targets,
        skill_name = "th_fengji",
        prompt = "#th_fengji&0",
        cancelable = false,
      })[1]
    end
    local card = Fk:getCardById(effect.cards[1])
    minoriko:addSkillUseHistory("th_fengji")
    room:addPlayerMark(minoriko, "@th_fengji", 1)
    room:obtainCard(minoriko, card, false, fk.ReasonGive, player)
    local _, dat = room:askToUseActiveSkill(minoriko, {
      skill_name = "#th_fengji_ag",
      prompt = "#th_fengji-ag:"..player.id.."::"..minoriko:getMark("@th_fengji"),
      cancelable = true,
      extra_data = {
        skillName = "th_fengji",
        first_target = player.id
      }
    })
    if dat then
      local card2 = Fk:cloneCard("amazing_grace")
      card2:addSubcards(dat.cards)
      card2.skillName = "th_fengji"
      room:useCard{
        from = minoriko,
        tos = dat.targets,
        card = card2,
      }
    end
  end,
})

Fk:loadTranslationTable{
  ["th_fengji&"] = "丰祭",
  [":th_fengji&"] = "出牌阶段限一次，你可以交给穰子一张红色手牌，然后其可以将X张红色手牌当【五谷丰登】对包括你的任意名角色使用（X为其的上个回合结束后此技能发动的次数）。",
  ["#th_fengji&"] = "丰祭：交给%src一张红色手牌，然后其可以将%arg张红色手牌当【五谷丰登】对包括你的任意名角色使用",
  ["#th_fengji&0"] = "丰祭：交给穰子一张红色手牌，然后其可以将至少一张红色手牌当【五谷丰登】对包括你的任意名角色使用",

  ["#th_fengji"] = "丰祭：将%arg张红色手牌当【五谷丰登】对包括你的任意名角色使用",

  ["#th_fengji-ag"] = "丰祭：你可以将%arg张红色手牌当【五谷丰登】对包括 %src 的任意名角色使用",
}

return fengji_other